package com.googlecode.yoohoo.xmppcore.protocol.parsing;

import com.googlecode.yoohoo.utils.Utils;

public class ProtocolKey {
	private String localName;
	private String namespace;
	
	public ProtocolKey() {
		this(null);
	}
	
	public ProtocolKey(String namespace) {
		this(null, namespace);
	}
	
	public ProtocolKey(String localName, String namespace) {
		this.localName = localName;
		this.namespace = namespace;
	}
	
	public String getLocalName() {
		return localName;
	}
	
	public void setLocalName(String name) {
		this.localName = name;
	}
	
	public String getNamespace() {
		return namespace;
	}
	
	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}
	
	@Override
	public int hashCode() {
		return (localName == null ? 0 : localName.hashCode()) +
			(namespace == null ? 0 : namespace.hashCode());
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ProtocolKey) {
			ProtocolKey other = (ProtocolKey)obj;
			return Utils.equalsEvenNull(localName, other.localName) &&
					Utils.equalsEvenNull(namespace, other.namespace);
		}
		
		return false;
	}
	
}
